package cn.itsource.basic.controller;

import cn.itsource.basic.dto.PhoneRegisterDto;
import cn.itsource.basic.service.VerifyCodeService;
import cn.itsource.basic.util.AjaxResult;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

/**
 * 验证码controller
 */
@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private VerifyCodeService verifyCodeService;


    /**
     * 获取图形验证码
     *
     */
    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult imageCode(@PathVariable("imageCodeKey") String imageCode) throws IOException {
        String base64ImageStr = verifyCodeService.imageCode(imageCode);
        return AjaxResult.me().success(base64ImageStr);

    }


    /**
     * 发送短信验证码
     *
     */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody PhoneRegisterDto dto) throws IOException {
        verifyCodeService.smsCode(dto);
        return AjaxResult.me().success();

    }
    /**
     * 手机号注册接口
     *
     */
    @PostMapping("/phoneRegister")
    public AjaxResult phoneRegister(@RequestBody PhoneRegisterDto dto) throws IOException {
        verifyCodeService.phoneRegister(dto);
        return AjaxResult.me().success();

    }
}
